package com.hanrui.android.activity.message.meet;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.MeetingDetailBean;
import com.hanrui.android.net.contract.message.meet.MeetingDetailContract;
import com.hanrui.android.net.presenter.message.meet.MeetingDetailPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的会议详情
 */
public class MeetingDetailActivity extends ActionBarBaseActivity<MeetingDetailPresenter> implements MeetingDetailContract.View {

    String mid;
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.enclosure_ll)
    LinearLayout enclosureLl;
    @BindView(R.id.enclosure)
    ImageView enclosure;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.copies_num)
    TextView copiesNum;
    @BindView(R.id.time_limit)
    TextView timeLimit;
    @BindView(R.id.leaders)
    TextView leaders;
    @BindView(R.id.from)
    TextView from;
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;



    @Override
    protected void initInjector() {mActivityComponent.inject(this);}

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meetingdetail);

        unbinder = ButterKnife.bind(this);

        mTitleBar.setTitle("会议详情");

        mid = getIntent().getStringExtra("mid");

        mPresenter.meetingBizDetail(this,mid);


    }


    @Override
    public void meetingBizDetail(final MeetingDetailBean data) {

        if (null != data) {


            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                enclosure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        MyDownLoadActivity.start(MeetingDetailActivity.this,data.getFiles());

                    }
                });

            		}

            mainTitle.setText(data.getMeeting().getName());
            subheadTitle.setText(data.getMeeting().getWarningDate());
            name.setText(data.getMeeting().getName());
            thingTitle.setText(data.getMeeting().getTypeName());
            time.setText(data.getMeeting().getLocation());
            pageNum.setText(data.getMeeting().getWarningDate());
            copiesNum.setText(data.getMeeting().getMeetingDateStart());
            timeLimit.setText(data.getMeeting().getMeetingDateEnd());
            leaders.setText(data.getMeeting().getMeetingGoods());
            from.setText(data.getMeeting().getRemarks());

            if (null != data.getMeetingIssueApplys() && data.getMeetingIssueApplys().size() > 0) {

                lladdview.setVisibility(View.VISIBLE);
                for (int i = 0; i < data.getMeetingIssueApplys().size(); i++) {

                    addViewItem(data.getMeetingIssueApplys().get(i));

                }

            		}

        		}

    }

    //添加ViewItem
    private void addViewItem(final MeetingDetailBean.MeetingIssueApplysBean bean) {
        View hotelEvaluateView = View.inflate(this, R.layout.item_meetingdetail, null);
        TextView miniTitle = hotelEvaluateView.findViewById(R.id.mini_title);
        TextView thingTitle = hotelEvaluateView.findViewById(R.id.thing_title);
        TextView time = hotelEvaluateView.findViewById(R.id.time);
        TextView agree = hotelEvaluateView.findViewById(R.id.agree);
        LinearLayout enclosureLl = hotelEvaluateView.findViewById(R.id.enclosure_ll);
        ImageView enclosure = hotelEvaluateView.findViewById(R.id.enclosure);

        miniTitle.setText(bean.getIssue());
        thingTitle.setText(bean.getCompanyName());
        time.setText(bean.getShowOfficeName());
        agree.setText(bean.getName());

        if (null != bean.getFiles() && bean.getFiles().size() > 0) {

            enclosureLl.setVisibility(View.VISIBLE);
            enclosure.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    MyDownLoadActivity.start(MeetingDetailActivity.this,bean.getFiles());

                }
            });

        		}


        lladdview.addView(hotelEvaluateView);
    }



    public static void start(Context context, String mid){

        Intent intent = new Intent(context,MeetingDetailActivity.class);
        intent.putExtra("mid",mid);
        context.startActivity(intent);
    }
}
